
import java.util.*;

public class Test {
    public static void main(String[] args){

    }
    //只出现一次的数字(异或做法)
    public int singleNumber1(int[] nums) {
        int ret = 0;
        for(int i = 0; i < nums.length; i++){
            ret ^= nums[i];
        }
        return ret;
    }
    //只出现一次的数字(哈希表)
    public int singleNumber2(int[] nums) {
        Set<Integer> set = new HashSet();
        for(int i = 0; i < nums.length; i++){
            if(!set.contains(nums[i])){
                set.add(nums[i]);
            }else{
                set.remove(nums[i]);
            }
        }
        for(int i = 0; i < nums.length; i++){
            if(set.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }
    //宝石与石头(哈希表)
    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> str1 = new HashSet<>();
        for(int i = 0; i < jewels.length(); i++){
            char ch = jewels.charAt(i);
            str1.add(ch);
        }
        int count = 0;
        for(int i = 0; i < stones.length(); i++){
            char ch = stones.charAt(i);
            if(str1.contains(ch)){
                count++;
            }
        }
        return count;
    }
    //坏键盘打字
    public static void func(String str1, String str2){
        Set<Character> set1 = new HashSet<>();
        for(int i = 0; i < str2.length(); i++){
            char ch = str2.charAt(i);
            set1.add(ch);
        }
        List<Character> list = new ArrayList<>();
        Set<Character> set2 = new HashSet<>();
        for(int i = 0; i < str1.length(); i++){
            char ch = str1.charAt(i);
            if(!set1.contains(ch) && !set2.contains(ch)){
                list.add(ch);
                set2.add(ch);
            }
        }
        for(int i = 0; i < list.size(); i++){
            System.out.print(list.get(i));
        }
    }
}
